<?php
/**
 * @Author: liuhongbin
 * @Email: 514660094@qq.com
 * @Date: 2019-02-12 16:15:10
 * @Description:
 * @LastEditors: liuhongbin
 * @LastEditTime: xxx
 */

namespace hiduoke\services;

use app\common\model\platform\PlatformWechat;
use think\Exception;
use hiduoke\services\wechat\traits\WechatAccountService;
use hiduoke\services\wechat\traits\WechatOrderService;

class WechatService
{
    // 平台id
    protected $plaid;

    // 应用名称
    protected $addon_name;

    // 公众号信息
    protected $wechat;

    //微信支付
    use WechatOrderService;

    //微信公众平台
    use WechatAccountService;

    public $err_msg = '';

    public function __construct($plaid = 0, $addon = '')
    {
        $this->init($plaid, $addon);
        $this->getApp();
    }

    /**
     * @param int $plaid
     * @param string $addon
     */
    protected function init($plaid = 0, $addon = '')
    {
        $this->plaid = $plaid ?: get_plaid();
        if (!$this->plaid) {
            throw new Exception(lang('The platform does not exist or has been deleted'), 10000);
        }
        if ($addon) {
            $this->addon_name = $addon;
        } else {
            $this->addon_name = input('addon', '');
        }
        $this->wechat = (new PlatformWechat())->where(['plaid' => $this->plaid])->find();
    }
}
